/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Day09_Ex6_genericStack;

import java.util.ArrayList;

/**
 *
 * @author Mark
 */
public class Stack<T>
{

    private ArrayList<T> elements;

    public Stack()
    {
        this(10);
    }

    public Stack(int capacity)
    {
        int initCapacity = capacity > 0 ? capacity : 10;
        elements = new ArrayList<T>(initCapacity);
    }

    public void push(T pushValue)
    {
        elements.add(pushValue);
    }

    public T pop()
    {
        if (elements.isEmpty())
        {
            throw new EmptyStackException("Stack is empty, cannot pop");
        }

        return elements.remove(elements.size() - 1);
    }
}
